package com.example.teaching_server.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 活动签到实体类
 */
@Getter
@Setter
@ToString(exclude = {"activity", "images"})
@EqualsAndHashCode(of = "id")
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "activity_checkins", indexes = {
        @Index(name = "idx_checkin_activity_user", columnList = "activity_id,user_id"),
        @Index(name = "idx_checkin_date", columnList = "check_date")
})
public class ActivityCheckinEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "activity_id")
    @NotNull(message = "活动不能为空")
    private ActivityEntity activity;

    @Column(name = "activity_id", insertable = false, updatable = false)
    private Long activityId;

    @Column(name = "user_id", nullable = false)
    @NotNull(message = "用户ID不能为空")
    private Long userId;

    @Column(name = "check_date", nullable = false)
    @NotNull(message = "签到日期不能为空")
    private LocalDate checkDate;

    @Column(name = "check_time", nullable = false)
    @NotNull(message = "签到时间不能为空")
    private LocalTime checkTime;

    @Column(length = 500)
    private String description;

    @CreationTimestamp
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;

    @OneToMany(mappedBy = "checkin", cascade = CascadeType.ALL)
    private List<ActivityCheckinImageEntity> images;

    @Column(name = "checkin_type", length = 20)
    private String checkinType;
}
